#ifndef     __SENSOR_H
#define     __SENSOR_H

#include "../utils/object.h"
#include "../utils/nocopyable.h"
#include "../rtos/mutex.h"
#include "../utils/base.h"

namespace driver {

class Sensor : private utils::NoCopyable {

public:
    static constexpr uint8_t BIT_OFFSET_JAW_OPEN = 0;
    static constexpr uint8_t BIT_OFFSET_JAW_CLOSE = 1;
    static constexpr uint8_t BIT_OFFSET_FILM_DROP = 2; // 检查封膜机有没有杯子在上面
    static constexpr uint8_t BIT_OFFSET_FILM_CARGO = 3; // 封膜机有没有在前面
    static constexpr uint8_t BIT_OFFSET_STEP_ZERO = 4;

    Sensor();

    inline bool is_jaw_open() {
        return utils::is_clr_bit<0>(read());
    }

    inline bool is_jaw_close() {
        return utils::is_clr_bit<1>(read());
        return 0x00 == (read() & (0x01 << BIT_OFFSET_JAW_CLOSE));
    }

    inline bool is_film_drop() {
        return utils::is_clr_bit<2>(read());
    }

    inline bool is_film_cargo() {
        return utils::is_clr_bit<3>(read());
    }

    inline bool is_step_origin() {
        return utils::is_set_bit<4>(read());
    }

    uint8_t status();

private:
    uint8_t read();
    rtos::Mutex m_mutex;
};

inline utils::Object<Sensor> sensor;

}

#endif
